home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1996, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /* solar5.c - a simple solar system.
- *
- * F1 key - print help information
- * SPACE Key - toggle between solid/wireframe models
- * Escape Key - exit program
- */
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
-
- #include <stdio.h>
- #include <math.h>
-
- /* Function Prototypes */
-
- GLvoid initgfx( GLvoid );
- GLvoid keyboard( GLubyte, GLint, GLint );
- GLvoid specialkeys( GLint, GLint, GLint );
- GLvoid drawScene( GLvoid );
-
- void checkError( char * );
- void printHelp( char * );
-
- /* Global Variables */
-
- static char *progname;
-
- static GLboolean filledFlag = GL_TRUE;
-
- /* Global Definitions */
-
- #define KEY_ESC 27 /* ascii value for the escape key */
-
- void
- main( int argc, char *argv[] )
- {
- GLsizei width, height;
-
- glutInit( &argc, argv );
-
- /* create a window that is 1/4 the size of the screen,
- * and position it in the middle of the screen.
- */
- width = glutGet( GLUT_SCREEN_WIDTH );
- height = glutGet( GLUT_SCREEN_HEIGHT );
- glutInitWindowPosition( width / 4, height / 4 );
- glutInitWindowSize( width / 2, height / 2 );
- glutInitDisplayMode( GLUT_RGBA );
- glutCreateWindow( argv[0] );
-
- initgfx();
-
- glutKeyboardFunc( keyboard );
- glutSpecialFunc( specialkeys );
- glutDisplayFunc( drawScene );
-
- progname = argv[0];
-
- printHelp( progname );
-
- glutMainLoop();
- }
-
- void
- printHelp( char *progname )
- {
- fprintf(stdout,
- "\n%s - model some objects\n\n"
- "F1 key - print help information\n"
- "SPACE key - toggle between solid/wireframe mode\n"
- "Escape Key - exit the program\n\n",
- progname);
- }
-
- GLvoid
- initgfx( GLvoid )
- {
- /* set clear color to black */
- glClearColor( 0.0, 0.0, 0.0, 1.0 );
-
- glMatrixMode( GL_PROJECTION );
- gluPerspective( 45.0, 1.0, 1.0, 20.0 );
- glMatrixMode( GL_MODELVIEW );
- }
-
- void
- checkError( char *label )
- {
- GLenum error;
- while ( (error = glGetError()) != GL_NO_ERROR )
- printf( "%s: %s\n", label, gluErrorString(error) );
- }
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- switch (key) {
- case ' ': /* toggle fill mode */
- filledFlag = !filledFlag;
- glutPostRedisplay();
- break;
- case KEY_ESC: /* Exit when the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- specialkeys( GLint key, GLint x, GLint y )
- {
- switch (key) {
- case GLUT_KEY_F1: /* Function key #1 */
- /* print help information */
- printHelp( progname );
- break;
- }
- }
-
- GLvoid
- drawScene( GLvoid )
- {
- static GLfloat year = 45.0, day = -90.0;
-
- static GLfloat yellow[] = { 1.0, 1.0, 0.0, 1.0 };
- static GLfloat blue[] = { 0.0, 0.0, 1.0, 1.0 };
- static GLfloat gray[] = { 0.2, 0.2, 0.2, 1.0 };
-
- glClear( GL_COLOR_BUFFER_BIT );
-
- glPushMatrix();
-
- /* move into the viewing volume */
- glTranslatef( 0.0, 0.0, -10.0 );
-
- /* draw sun */
-
- glPushMatrix();
-
- /* Give the sun a yellow glow */
- glColor4fv( yellow );
-
- /* rotate on our own axis */
- glRotatef( 90.0, 1.0, 0.0, 0.0 );
- if (filledFlag)
- glutSolidSphere( 0.7, 15, 15 );
- else
- glutWireSphere( 0.7, 15, 15 );
-
- glPopMatrix();
-
- glPushMatrix();
-
- /* draw earth */
-
- /* rotate to the right time of year */
- glRotatef( year, 0.0, 1.0, 0.0 );
-
- /* translate out to our orbit about the sun */
- glTranslatef( 3.5, 0.0, 0.0 );
- glPushMatrix();
-
- /* set color for the earth */
- glColor4fv( blue );
-
- /* rotate on our own axis */
- glRotatef( 90.0, 1.0, 0.0, 0.0 );
- if (filledFlag)
- glutSolidSphere( 0.4, 15, 15 );
- else
- glutWireSphere( 0.4, 15, 15 );
-
- glPopMatrix();
-
- /* draw moon */
- glPushMatrix();
-
- /* set color for the moon */
- glColor4fv( gray );
-
- /* rotate to the right time of day */
- glRotatef( day, 0.0, 1.0, 0.0 );
-
- /* translate out to our orbit about the earth */
- glTranslatef( 1.0, 0.0, 0.0 );
-
- /* rotate on our axis */
- glRotatef( 90.0, 1.0, 0.0, 0.0 );
- if (filledFlag)
- glutSolidSphere( 0.2, 15, 15 );
- else
- glutWireSphere( 0.2, 15, 15 );
-
- glPopMatrix();
-
- glPopMatrix();
-
- glPopMatrix();
-
- checkError( "drawScene" );
-
- glFlush();
- }
-